package com.qdu.hyy.MovieGenreCount;
import com.qdu.hyy.util.testJson;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class MovieGenreCountDriver {

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "Movie Analysis");

        job.setJarByClass(MovieGenreCountDriver.class);

        // 设置Mapper类
        job.setMapperClass(MovieGenreCountMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        // 设置Combiner类（如果需要的话）
        // job.setCombinerClass(MovieCombiner.class);

        // 设置Reducer类
        job.setReducerClass(MovieGenreCountReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        // 设置输入和输出路径
        FileInputFormat.addInputPath(job, new Path("input/hyy/movies_complete.csv"));
        FileOutputFormat.setOutputPath(job, new Path("output/job1"));

        int a=job.waitForCompletion(true) ? 0 : 1;
        testJson.readFromHdfs("hdfs://niit-master:9000/user/niit/output/job1/part-r-00000");

        // 提交作业并等待完成
        System.exit(a);
    }

}
